package com.yyk.yiliao.ui.activity.dingdan.activity;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.appcompat.widget.Toolbar;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yyk.yiliao.R;
import com.yyk.yiliao.base.BaseActivity;
import com.yyk.yiliao.base.BaseRecyclerAdapter;
import com.yyk.yiliao.base.BaseRecyclerHolder;
import com.yyk.yiliao.util.TimerUtil;
import com.yyk.yiliao.util.rx.ApiService;
import com.yyk.yiliao.bean.OrderOrderRestart_Info;
import com.yyk.yiliao.widget.diver.CustomDecoration;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.List;

import butterknife.BindView;

public class DingdanXiangqing_Activity extends BaseActivity {

    @BindView(R.id.mMember_upadte)
    TextView mMemberUpadte;
    @BindView(R.id.ll_qxdd)
    LinearLayout llQxdd;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.tv_status)
    TextView tvStatus;
    @BindView(R.id.tv_address)
    TextView tvAddress;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_phone)
    TextView tvPhone;
    @BindView(R.id.tv_stname)
    TextView tvStname;
    @BindView(R.id.rv)
    RecyclerView rv;
    @BindView(R.id.tv_total)
    TextView tvTotal;
    @BindView(R.id.tv_total2)
    TextView tvTotal2;
    @BindView(R.id.tv_number)
    TextView tvNumber;
    @BindView(R.id.tv_addtime)
    TextView tvAddtime;


    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_dingdan_xiangqing;
    }

    @Override
    public void initView() {
        initToolbar();
    }

    private void initToolbar() {
        setBackArrow();
        setTitle("订单详情");
    }

    @Override
    public void initData() {
        EventBus.getDefault().register(this);
    }

    @Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
    public void onMessageww(OrderOrderRestart_Info info) {
        OrderOrderRestart_Info.AddressBean address = info.getAddress();
        if (address != null) {
            String dizhi = address.getAddress();
            tvAddress.setText(dizhi);
            tvName.setText(address.getName());
            tvPhone.setText(address.getPhone());
        }
        tvTotal.setText("¥" + info.getTotal());
        tvTotal2.setText("¥" + info.getTotal());

        String timer = TimerUtil.get(info.getAddtime());
        tvAddtime.setText(timer);
        OrderOrderRestart_Info.DataBean dataBean = info.getData().get(0);
        tvStname.setText(dataBean.getSname());
        tvNumber.setText(dataBean.getNumber());
        List<OrderOrderRestart_Info.DataBean.GoodslistBean> data = dataBean.getGoodslist();
        final BaseRecyclerAdapter<OrderOrderRestart_Info.DataBean.GoodslistBean> adapter = new BaseRecyclerAdapter<OrderOrderRestart_Info.DataBean.GoodslistBean>(DingdanXiangqing_Activity.this, data, R.layout.zk) {
            @Override
            public void convert(BaseRecyclerHolder holder, final OrderOrderRestart_Info.DataBean.GoodslistBean goodslistBean, final int position, boolean isScrolling) {
                holder.setText(R.id.tv_num, "X" + goodslistBean.getNum());
                holder.setText(R.id.tv_money, "¥" + goodslistBean.getMoney());
                holder.setText(R.id.tv_sname, goodslistBean.getName());
                holder.setImageByUrl(R.id.iv_img, ApiService.BASE_URL + goodslistBean.getImg());
            }
        };
        rv.setLayoutManager(new LinearLayoutManager(DingdanXiangqing_Activity.this));
        rv.addItemDecoration(new CustomDecoration(DingdanXiangqing_Activity.this, CustomDecoration.VERTICAL_LIST, R.drawable.divider_f8_shopdingdan, 0));
        rv.setAdapter(adapter);


    }
}
